from django.db import models
from product.models import Product
# Create your models here.

#场景用例表
class Apitest(models.Model):
    product = models.ForeignKey('product.Product', on_delete=models.CASCADE,null=True) #product.Product 应用.表
    apitestname = models.CharField('流程接口名称',max_length=64)
    apitestdesc = models.CharField('描述',max_length=64,null=True)  #流程接口
    apitester = models.CharField('测试负责人',max_length=32)  #流程接口
    apitestresult = models.BooleanField('测试结果')  #流程接口
    created_time = models.DateTimeField('创建时间', auto_now_add=True)
    #当前时间
    class Meta:
        verbose_name = '流程场景接口'
        verbose_name_plural = '流程场景接口'
    def __str__(self):
        return self.apitestname

#场景用例步骤
class Apistep(models.Model):
    Apitest = models.ForeignKey('Apitest', on_delete=models.CASCADE)  #关联接口ID
    apiname = models.CharField('接口名称', max_length=100)
    apiurl = models.CharField('url地址', max_length=500)
    apistep = models.CharField('测试步骤', max_length=100,null=True)
    apiparamvalue = models.TextField('请求参数和值', max_length=4096)
    REQUEST_METHOD = (('get', 'get'),('post','post'),('put', 'put'),('delete', 'delete'),('patch','patch'))
    apimethod = models.CharField(verbose_name='请求方法',choices=REQUEST_METHOD,default='get', max_length=200, null=True)  #请求方法
    apiresult = models.CharField('预期结果', max_length=200)
    apiresponse = models.TextField('响应数据', max_length=5000,null=True)
    apistatus = models.BooleanField('是否通过')
    created_time = models.DateTimeField('创建时间', auto_now_add=True)
    def __str__(self):
        return self.apiname
#单接口
class Apis(models.Model):
    Product = models.ForeignKey('product.Product',on_delete=models.CASCADE,null=True)
    apiname = models.CharField('接口名称',max_length=100)
    apiurl = models.CharField('url地址',max_length=200)
    apiparamvalue = models.TextField('请求参数和值',max_length=4096)
    REQUEST_METHOD = (('0','get'),('1','post'),('2','put'),('3','delete'),('4','patch'))
    apimethod = models.CharField(verbose_name='请求方法', choices=REQUEST_METHOD,default=0,max_length=200)
    apiresult = models.CharField('预期结果', max_length=200)
    apistatus = models.BooleanField('是否通过')
    created_time = models.DateTimeField('创建时间', auto_now_add=True)
    class Meta:
        verbose_name = '单一场景接口'
        verbose_name_plural = '单一场景接口'
    def __str__(self):
        # dicts = {'apiname':self.apiname,'apiurl':self.apiurl}
        return self.apiname

#系统设置后台
class Set(models.Model):
    setname = models.CharField('系统名称', max_length=64)
    setvalue = models.CharField('系统设置',max_length=200)
    class Meta:
        verbose_name = '系统设置'
        verbose_name_plural = '系统设置'
    def __str__(self):
        return self.setname